package com.htsk.city.services.admin.aspect;

import com.htsk.city.services.admin.annotation.RequireRole;
import com.htsk.city.services.admin.service.UserService;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Aspect
@Component
public class RoleAspect {

    @Resource
    private UserService userService;
    @Around("@annotation(requireRole)")
    public Object checkRole(ProceedingJoinPoint joinPoint,
                            RequireRole requireRole) throws Throwable {
        String requiredPerm = requireRole.value();
        userService.checkRole(requiredPerm);
        return joinPoint.proceed();
    }
}

